var tid = 0;
var hid = 0;
var Toast = (function () {
    function Toast() {
        var ps = getCurrentPages();
        var cs = ps[ps.length - 1];
        this.page = cs;
        this.t = 0;
        this.title = "";
        this.config = { duration: 3000 };
    }
    Toast.prototype.hide = function () {
        let ani = wx.createAnimation({
            duration: 100,
            timingFunction: 'linear', // "linear","ease","ease-in","ease-in-out","ease-out","step-start","step-end"
            delay: 0,
            transformOrigin: '50% 50% 0',
        });
        ani.opacity(0).step();
        this.config.animation = ani.export();
        this.page.setData({
            toast: this.config
        });

        hid=setTimeout(() => {
            if (this.config.complete) this.config.complete();
            this.config.is_show = false;
            this.page.setData({
                toast: this.config
            });
        }, 100);
    }
    Toast.prototype.show = function (data) {
        if (!data) {
            data = {};
        }
        if (!data.duration) {
            data.duration = 3000;
        }
        for (var k in data) {
            this.config[k] = data[k];
        }

        this.config.is_show = true;
        let ani = wx.createAnimation({
            duration: 100,
            timingFunction: 'linear', // "linear","ease","ease-in","ease-in-out","ease-out","step-start","step-end"
            delay: 0,
            transformOrigin: '50% 50% 0',
        });
        ani.opacity(1).step({ delay: 10 });
        this.config.animation = ani.export();
        clearTimeout(tid);
        clearTimeout(hid);
        if (this.config.duration > 0) {
            tid = setTimeout(() => {
                this.hide();
            }, this.config.duration);
        }

        this.page.setData({
            toast: this.config
        })
    }

    Toast.prototype.loading = function (data) {
        if (!data) data = {};
        data.duration = -1;
        this.show(data);
    }

    Toast.prototype.reset = function () {
        this.config.title = "";
        this.config.duration = 3000;
    }



    return Toast;
})();

let ele = new Toast();
function init() {
    var ps = getCurrentPages();
    var cs = ps[ps.length - 1];
    cs.toast = new Toast();
}
module.exports = {
    init
}